<?php

/**
 * Remove an user.
 */
class sfGuardUpdatePasswordTask extends sfBaseTask
{
	
  /**
   * @see sfTask
   */
  protected function configure()
  {
    $this->addArguments(array(
      new sfCommandArgument('username', sfCommandArgument::REQUIRED, 'The username'),
      new sfCommandArgument('newpass', sfCommandArgument::REQUIRED, 'The new password'),
      new sfCommandArgument('application', sfCommandArgument::OPTIONAL, 'The application name','ui')
    ));


    $this->namespace = 'guard';
    $this->name = 'update-password';
    $this->briefDescription = 'Update the user password';

    $this->detailedDescription = <<<EOF
The [guard:update-password|INFO] task update the userpassword:

  [./symfony guard:update-password username newpass|INFO]
EOF;
  }

  /**
   * @see sfTask
   */
  protected function execute($arguments = array(), $options = array())
  {
	$databaseManager = new sfDatabaseManager($this->configuration);

    if(!LdapLogin::updatePassword($arguments['username'],$arguments['newpass']))
        throw new Exception('User does not exists in LDAP database');
    
    $user = Doctrine::getTable("sfGuardUser")->findByUsername($arguments['username'])->getFirst();
	$user->setPassword($arguments['newpass']);
	$user->save();
	$this->log("Done");
    

  }
  
}